<template>
  <div>
    <el-dialog :title="info.isadd?'管理员添加':'管理员修改'" :visible.sync="info.isshow" @closed="closed">
      {{form}}
      <el-form :model="form">
        <el-form-item label="手机号" label-width="120px">
          <el-input v-model="form.phone" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="昵称" label-width="120px">
          <el-input v-model="form.nickname" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="密码" label-width="120px">
          <el-input v-model="form.password" autocomplete="off"></el-input>
         密  码  留  空  则  不  修  改 ! ! ! ! ! !
        </el-form-item>

        <el-form-item label="状态" label-width="120px">
          <el-switch v-model="form.status" :active-value="1" :inactive-value="2"></el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="qx">取 消</el-button>
        <el-button type="primary" @click="xiugai">修 改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {reqmemberinfo, reqmemberedit } from "../../../request/api";
import { successAlert,errorAlert} from "../../../utils/alert";
import { mapActions, mapGetters } from "vuex";
export default {
  props: ["info"],
  data() {
    return {
      form: {
        phone: "",
        nickname: "",
        password: "",
        status: "2",
      },
    };
  },
  computed: {
    ...mapGetters({
      list: "vip/list",
    }),
  },
  methods: {
    ...mapActions({
      reqlist: "vip/reqlist",
    }),
    closed() {
      if (!this.info.isadd) {
        this.empty();
      }
    },
    qx() {
      this.info.isshow = false;
    },
    empty() {
      this.form = {
        phone: "",
        nickname: "",
        password: "",
        status: "2",
      };
    },
    one(uid) {
      // console.log(uid);
      reqmemberinfo({ uid: uid }).then((res) => {
        this.form = res.data.list;
        this.form.password = "";
        this.form.uid=uid
      });
    },
     checkEmpty() {
      return new Promise((resolve, reject) => {
        if (this.form.phone == "") {
          errorAlert("手机号不能为空");
          return;
        }
        if (this.form.nickname == "") {
          errorAlert("昵称不能为空");
          return;
        }
        if (this.form.password == "") {
          errorAlert("密码不能为空");
          return;
        }
        resolve();
      });
    },
    //修改
    xiugai() {
      this.checkEmpty().then(()=>{
        reqmemberedit(this.form).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.info.isshow = false;
          this.empty();
          this.$emit("init");
          this.reqlist()
        }
      });
      }) 
    },
  },
};
</script>

<style>
</style>